package homeadapter;

import android.content.Context;
import android.support.v7.view.menu.MenuView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.yztc.thinkpad.mandemo.R;

import java.util.List;

import homebean.BangBangBean;
import homebean.HomevpBean;

/**
 *首页的 GrideView加载邦邦精选
 * Created by Administrator on 2016/10/7.
 */
public class GrideBangBangViewAdapter extends BaseAdapter {
    private Context context;
    private List<BangBangBean.DataBean.ItemDetailBean> mList;
    public GrideBangBangViewAdapter(Context context, List<BangBangBean.DataBean.ItemDetailBean> mList) {
        this.context = context;
        this.mList = mList;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder mViewHolder;
        if (view==null){
            view= LayoutInflater.from(context).inflate(R.layout.home_bang_gv_item,viewGroup,false);
            mViewHolder=new ViewHolder();
            mViewHolder.bang_gv_iv= (ImageView) view.findViewById(R.id.bang_gv_iv);
            mViewHolder.home_bang_gv_title= (TextView) view.findViewById(R.id.home_bang_gv_title);
            mViewHolder.home_bang_gv_price= (TextView) view.findViewById(R.id.home_bang_gv_price);
            view.setTag(mViewHolder);
        }else{
            mViewHolder= (ViewHolder) view.getTag();
        }
        if (mList.size()==0){
            Toast.makeText(context,"数据加载完成",Toast.LENGTH_LONG).show();
        }
        mViewHolder.home_bang_gv_price.setText(mList.get(i).getCoupon_price());
        mViewHolder.home_bang_gv_title.setText(mList.get(i).getTitle());
        Glide.with(context).load(mList.get(i).getPic_url())
                .placeholder(R.mipmap.default_place_hold_image)
                .into(mViewHolder.bang_gv_iv);
        return view;
    }
    static  class ViewHolder{
      ImageView bang_gv_iv;
      TextView home_bang_gv_title,home_bang_gv_price ;
    }
}
